package com.pro.service.imple;

import com.pro.mapper.LoginMapper;
import com.pro.mapper.NavigationBarMapper;
import com.pro.pojo.JsCarousel;
import com.pro.pojo.JsMenu;
import com.pro.pojo.JsUser;
import com.pro.pojo.LoginRecord;
import com.pro.service.NavigationBarService;
import com.pro.utils.RedisCache;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;

/**
 * @author ：刘弘禹
 * @description：TODO
 * @date ：2022/1/10 14:29
 */

@Service
public class NavigationBarServiceImple implements NavigationBarService {
    @Autowired
    private UserDetailsService userDetailsService;

    @Autowired
    private LoginMapper loginMapper;

    @Autowired
    private RedisCache redisCache;

    @Autowired
    private NavigationBarMapper navigationBarMapper;


    @Override
    public List<JsMenu> getJsMenus() {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        String name = authentication.getName();
        UserDetails userDetails = userDetailsService.loadUserByUsername(name);
        JsUser login = loginMapper.login(name, userDetails.getPassword());
        List<JsMenu> cacheObject = (List<JsMenu>) redisCache.getCacheObject("deptId:" + login.getDeptId());
        return cacheObject;
    }

    /* 功能描述: <br>
     * 〈根据id获取登录日志〉
     *
     * @param id
     * @return: com.pro.pojo.LoginRecord
     * @Author: Kai
     * @Date: 2022/2/22 下午 03:10
     */
    @Override
    public List<LoginRecord> getLoginUserrById(Integer id) {
        List<LoginRecord> loginUserrById = navigationBarMapper.getLoginUserrById(id);
        return loginUserrById;
    }

    /* 功能描述: <br>
    * 〈统计提示信息〉
    *
    * @param id
	 * @param status
    * @return: java.util.HashMap<java.lang.String,java.lang.Object>
    * @Author: Kai
    * @Date: 2022/2/22 下午 03:45
    */
    @Override
    public HashMap<String, Object> getOrderQuantityStatus(Integer type) {
        HashMap<String, Object> map = new HashMap<>();

        Integer courseOrder = navigationBarMapper.getOrderQuantityStatus(2,0);
        Integer productOrder = navigationBarMapper.getOrderQuantityStatus(3,0);
        Integer returnRequest = navigationBarMapper.getOrderQuantityStatus(0,7);
        Integer shipin = navigationBarMapper.getShenHeNums(2);
        Integer shangpin = navigationBarMapper.getShenHeNums(3);
        Integer weiquan = navigationBarMapper.getShenHeNums(4);
        map.put("courseOrder", courseOrder);
        map.put("productOrder", productOrder);
        map.put("returnRequest", returnRequest);
        map.put("videoNoNums", shipin);
        map.put("productNoNums", shangpin);
        map.put("microCircleNoNums", weiquan);
        return map;
    }

    /* 功能描述: <br>
     * 〈查询广告信息〉
     *
     * @param
     * @return: com.pro.pojo.JsCarousel
     * @Author: Kai
     * @Date: 2022/2/22 下午 04:32
     */
    @Override
    public List<JsCarousel> getAllCarousel() {
        List<JsCarousel> allCarousel = navigationBarMapper.getAllCarousel();
        return allCarousel;
    }

}

